package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.dao.AdminDao;
import com.baizhi.cmfz.entity.Admin;
import com.baizhi.cmfz.service.AdminService;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao adminDao;

    @Override
    @Transactional(readOnly = true)
    public Admin login(String username) {
        return adminDao.login(username);
    }

    @Override
    public int addAdmin(Admin admin) {
        return adminDao.insertAdmin(admin);
    }

    @Override
    public int removeAdminById(int[] ids) {
        return adminDao.deleteAdminById(ids);
    }

    @Override
    public int updateAdmin(Admin admin) {
        return adminDao.updateAdmin(admin);
    }

    @Override
    @Transactional(readOnly = true)
    public Admin selectOneAdmin(int adminId) {
        return adminDao.selectAdminById(adminId);
    }

    @Override
    @Transactional(readOnly = true)
    public Map selectAllAdmin(int page, int limit) {
        page = (page - 1) * limit;
        Map<String, Object> map = new HashMap<>();
        map.put("data", adminDao.selectAllAdminByPage(page, limit));
        map.put("count", adminDao.countAdmin());
        map.put("code", 0);
        return map;
    }
}
